//
//  APIConstant.swift
//  ifanr
//
//  Created by 😱😱 on 16/9/12.
//  Copyright © 2016年 😱😱. All rights reserved.
//

import UIKit
import Foundation
import Moya

public enum APIConstant {
    /**
     *  首页-列表 每次请求12条
     *
     *  @param Int 参数page 分页数从1开始
     *
     */
    case Home_latest(Int)
}


extension APIConstant: TargetType {
    //MARK: ---------------------------基本默认要传入的参数 --------------------------
    /// appKey
    private var appKey: String {
        return "sg5673g77yk72455af4sd55ea"
    }
    
    private var excerpt_length: Int {
        return 80
    }
    
    private var sign: String {
        return "be072a0fc0b7020836bae8777f2fbeca"
    }
    
    /// 当前时间的时间戳
    private var timestamp: String {
        return NSDate.getCurrentTimeStamp()
    }
    

    private var post_type: String {
        switch self {
        case .Home_latest(_):
            return "post%2Cnews%2Cdasheng%2Cdata".stringByRemovingPercentEncoding!
        }
    }
    
    private var action: String {
        switch self {
        default:
            return "ifr_m_latest"
        }
    }
    
    private var posts_per_page: Int {
        return 12
    }
    
    //MARK: --------------------------- Path --------------------------
    /// url
    
    public var baseURL: NSURL {
        
        return NSURL(string: "https://www.ifanr.com/api/v3.0/")!
    }
    /// 路径
    public var path: String {
        
        return ""
    }
    /// 请求方法
    public var method: Moya.Method {
        return .GET
    }
    
    /// 请求参数
    public var parameters: [String: AnyObject]? {
        switch self {
        /// 首页列表
        case let .Home_latest(page):
            return ["action": action, "appKey": appKey, "excerpt_length": excerpt_length, "sign": sign, "timestamp": timestamp, "page": page, "posts_per_page": posts_per_page, "post_type": post_type]
        }
    }
    
//    public var multipartBody: [MultipartFormData]? {
//        return nil
//    }
    
    /// 单元测试用
    public var sampleData: NSData {
        return "{}".dataUsingEncoding(NSUTF8StringEncoding)!
    }
}